<template>
  <div class='top-category'>
    <div class="container" v-if="topCategory">
     <XtxBread>
      <XtxBreadItem to="/">首页</XtxBreadItem>
      <XtxBreadItem >{{topCategory.name}}</XtxBreadItem>
      </XtxBread>
    </div>
    <div v-else>loading.....</div>
  </div>
</template>

<script>
import { findTopCategory } from '@/api/category'
import { useRoute } from 'vue-router'
import { ref } from 'vue-demi'
export default {
  name: 'TopCategory',
  setup () {
    const topCategory = ref(null)
    // useRoute()方法 拿到点击路由带过来的值
    const route = useRoute()
    // 根据id获取分类数据
    findTopCategory(route.params.id).then(({ result }) => {
      topCategory.value = result
    })

    return { topCategory }
  },
  created () {
    console.log('组件创建了')
  },
  unmounted () {
    console.log('组件卸载了')
  }
}
</script>

<style scoped lang="less">
.top-category {
  h3 {
    font-size: 28px;
    color: #666;
    font-weight: normal;
    text-align: center;
    line-height: 100px;
  }
  .sub-list {
    margin-top: 20px;
    background-color: #fff;
    ul {
      display: flex;
      padding: 0 32px;
      flex-wrap: wrap;
      li {
        width: 168px;
        height: 160px;
        a {
          text-align: center;
          display: block;
          font-size: 16px;
          img {
            width: 100px;
            height: 100px;
          }
          p {
            line-height: 40px;
          }
          &:hover {
            color: @xtxColor;
          }
        }
      }
    }
  }
  .ref-goods {
    background-color: #fff;
    margin-top: 20px;
    position: relative;
    .head {
      .xtx-more {
        position: absolute;
        top: 20px;
        right: 20px;
      }
      .tag {
        text-align: center;
        color: #999;
        font-size: 20px;
        position: relative;
        top: -20px;
      }
    }
    .body {
      display: flex;
      justify-content: space-around;
      padding: 0 40px 30px;
    }
  }
}
</style>
